package com.yc.framework.config;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//@Component
public class InitJpa {
    //    @Value("${spring.datasource.druid.username}")
    @Value("root")
    private String username;
    @Value("root")
    private String password;
    @Value("jdbc:mysql://localhost:3306/used_books")
    private String url;
    @Value("com.mysql.cj.jdbc.Driver")
    private String driverClassName;

    @PostConstruct
    public void initActiveRecordPlugin() {
        DruidPlugin dp = new DruidPlugin(url, username, password, driverClassName);
        dp.set(3, 1, 3);
        ActiveRecordPlugin arp = new ActiveRecordPlugin("yysoft", dp);
        arp.setDialect(new MysqlDialect());
        arp.setShowSql(false);
        dp.start();
        arp.start();
        System.out.println(Db.use("yysoft").find("select * from sys_user"));
    }
}
